All Questions
Tagged with algorithmjavascript
489 questions
6votes
3answers
786views
Collision detection of two rects with rounded borders
I wrote an algorithm how to detect the collision detection of two rects with rounded borders (the code was written using TypeScript but I tried to name things as clear as possible to code be readable ...
6votes
1answer
182views
Code to generate an array of 364 random special characters with 20 random words broken up throughout
I am trying to recreate a Fallout 4 style terminal hacking game, so I wanted to create code to generate the terminal output (namely, 32 rows with 12 characters each and 20 random words spread out). ...
3votes
1answer
91views
Merge discrete integer intervals
What it does The code starts with a set of integer intervals, and can add new intervals (possibly by updating existing intervals). Essentially, it is a bit array whose index starts at ...
3votes
2answers
158views
Basic Linked List Implementation in JavaScript
Clarification of Intent Recursion here is used on purpose for practice - note that iteration is preferred in this case (I'll be more clear about where my intentions are!) Factory function was also ...
2votes
3answers
198views
Efficiently tagging first and last of each object matching condition
How can I make the code more readable and more efficient? (provided code is O(n²) time, but intuition says it can be pre-processed and done in O(n) time) Description it tags the first and last of ...
1vote
2answers
116views
A simple performant factorial function
I am new to algorithm and data structure. After a little introduction to the topic, I have decided to implement a function called calculateFactorial, which takes an integer and calculates its ...
1vote
1answer
57views
Negamax AI for playing Connect Four against Alpha-beta pruning AI in Javascript
The working page is in GitHub. Introduction This time, I have two AI bots playing Connect Four against each other. The first AI bot uses Alpha-beta pruning, and the other one uses a Negamax with Alpha-...
4votes
0answers
54views
Connect Four AI vs. AI match in Javascript
This time, I have a Javascript program that runs a Connect Four match between two Alpha-beta pruning based AI bots. (See this page.) ai-battle.html: ...
2votes
1answer
62views
Combining multiple regexps using the `|` operator and grouping the regexps by their flags
I've implemented a function that creates a multiple regular expressions predicate. The idea behind the predicate is combining regular expressions using the disjunction operator ...
3votes
2answers
95views
Optimizing a Function to Check Pronic Numbers in JavaScript
I've written a function in JavaScript to check whether a given number is a Pronic number. A Pronic number, also known as an oblong number, rectangular number, or ...
2votes
1answer
108views
Move timestamp to the next Monday 10:01 AM [closed]
I've been battling ChatGPT for hours now and can't get satisfied with this simple algorithm in TypeScript. These two (hopefully correct) TypeScript+ReactNative solutions should move the timestamp ...
7votes
1answer
232views
Find the longest "common sequence" in two lists
In short, the algorithm must find the longest sequence that joins together common sequences from two lists (a more formal specification is given in the code's header). The lists are assumed to contain ...
2votes
2answers
75views
Calculating the sum of all k-sized sub-arrays in an array using sliding window algorithm
I need to calculate the sum of all k-sized sub-arrays in an array using sliding window algorithm. Is that a valid sliding window algorithm? If not, why? ...
3votes
1answer
134views
4votes
2answers
341views
Count matching pairs (modular equality)
Problem Given an array of natural numbers a. Find the number of such pairs of elements (a_i, a_j), where ...